package com.itheima.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class test3 {
    public static void main(String[] args) throws IOException {
        //序列化多个对象
        Student s1 = new Student("yanxurui", 18, "北京");
        Student s2 = new Student("ouyangnana", 19, "上海");
        Student s3 = new Student("zhangsan", 20, "北京");

        //创建集合
        ArrayList<Student> list = new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //序列化
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("a.txt"));
        oos.writeObject(list);

        //释放资源
        oos.close();

    }
}
